/**
 * 
 */
package com.dalonedrow.pooled;

/**
 * Wrapper class for {@link stringBuilder}.
 * @author DaLoneDrow
 */
public final class PooledStringBuilder implements PoolableObject {

	private int				poolIndex;
	private StringBuffer	stringBuilder	= new StringBuffer(1000);
	/**
	 * 
	 */
	public PooledStringBuilder(final int index) {
		poolIndex = index;
	}
	public void append(final char value) {
		stringBuilder.append(value);
	}
	public void append(final char[] value) {
		stringBuilder.append(new String(value));
	}
	public void append(final float value) {
		stringBuilder.append(value);
	}
	public void append(final int value) {
		stringBuilder.append(value);
	}
	public void append(final long value) {
		stringBuilder.append(value);
	}
	public void append(final Object value) {
		stringBuilder.append(value.toString());
	}
	/**
	 * @see java.lang.String#valueOf(boolean)
	 * @see #append(java.lang.String)
	 */
	public void append(final String value) {
		stringBuilder.append(value);
	}
	public int getPoolIndex() {
		return poolIndex;
	}
	public void init() {
		// TODO Auto-generated method stub

	}
	public int length() {
		return stringBuilder.length();
	}
	public void returnToPool() {
		stringBuilder.setLength(0);
		if (StringBuilderPool.getInstance().isItemLocked(this)) {
			StringBuilderPool.getInstance().unlockItem(this);
		}
	}
	public void setLength(final int length) {
		stringBuilder.setLength(length);
	}
	@Override
	public String toString() {
		return stringBuilder.toString();
	}
}
